package com.jj.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {

    @RequestMapping("/demo")
    public String demo() {
        return "demo";
    }

    @RequestMapping("/getDemoInfo")
    @HystrixCommand(fallbackMethod = "hystrixGetDemoInfo")
    public String getDemoInfo(String name, int age) {
        if ("张三".equals(name)) {
            throw new RuntimeException("呔，法外狂徒！");
        }
        return "server1:getInfo:" + "name:" + name + ",age:" + age;
    }

    private String hystrixGetDemoInfo(String name, int age) {
        return "姓名：" + name + ",年龄" + age + "，此人极度危险，速速远离";
    }

}
